<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Mad Voter</title>
    <script src = "http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type = "text/javascript"></script>
</head>
<body>
    <h1 style="text-align:left">Times: <p id = "times" >0</p></h1>
    <iframe id="outSideWeb" width = "100%" height="20%"></iframe>
    <button id="Go" onclick="showChoice()" width = "10%" height = "5%" style="display:none; font-size:30px" >&nbsp;Go&nbsp;</button>
    <button id="Hit" onclick="Hit()" width = "10%" height = "5%" style="display:none; font-size:30px" >&nbsp;Hit&nbsp;</button>
    <button id="Stop" onclick="stopHit()" width = "10%" height = "5%" style="display:none; font-size:30px" >&nbsp;Stop&nbsp;</button>
    <button id="ChangeUrl" onclick="ChangeUrl()" width = "10%" height = "5%" style="display:none; font-size:30px" >&nbsp;ChangeUrl&nbsp;</button>
    <button id="Hit2" onclick="Hit2()" width = "10%" height = "5%" style="display:none; font-size:30px" >&nbsp;Hit2&nbsp;</button>    
    <p>先等待页面响应，响应完成后会出现"Go"按钮，如果响应内容是{"Result": "1"},说明可以继续投票，再点击"Hit"按钮，待出现{"Result": "0"}后请关闭页面或者点击"Stop"按钮。</p>
    <p>如果第一次就是{"Result": "0"}，请不要尝试继续投票。</p>
    <p>如果第一次页面响应后不是以上两种情况，请点击"ChangeUrl"按钮后等待页面响应，如果出现{"Result": "1"}，可点击"Hit2"进行投票，投票结束后请关闭或者点击"Stop"按钮。</p>
    <p>如果第一次提示的时间大于5s就请不要尝试使用了。</p>
    
<script>
    var url1 = "http://12316szntp.bjzntd.com/JSON/NVoteSubmit1.ashx?NewsID=10468&Type=0";
    var url2 = "http://12316szntp.bjzntd.com/JSON/NVoteSubmit.ashx?NewsID=10468&Type=0";
    var url;
    var times = 1;
    var startTime = new Date();
    var endTime = "" ;

    $(document).ready(function(){
        var iframe;
        loadAndShow();

        function loadAndShow() {  
            iframe = document.getElementById("outSideWeb");  
            iframe.onload = iframe.onreadystatechange = iframeload;   
            iframe.src = url1;  
        };

        function iframeload() {
            if (!iframe.readyState || iframe.readyState == "complete") {
                $("#Go").show();
                $("#ChangeUrl").show();
                endTime = new Date();
                alert((endTime - startTime)/1000 + "s");
                $("#times").html("1")
            ;}
        };

        
    });

    function showChoice(){
        if(confirm("\"Result\"是否显示 1 ？")){
            $("#Hit").show()
        }
    };

    function Hit(){
        interval1 = setInterval("doHit()",5000)
        $("#Stop").show()
    };

    function doHit(){
        iframe = document.getElementById("outSideWeb");  
        iframe.src = url1;
        times = times + 1
        $("#times").html(times)
    };
      
    function stopHit(){
        clearInterval(interval1);
        clearInterval(interval2);
    }

    function Hit2(){
        interval2 = setInterval("doHit2()",5000)
    };

    function doHit2(){
        iframe = document.getElementById("outSideWeb");  
        iframe.src = url2;
        times = times + 1
        $("#times").html(times)
        console.log(times)
        $("#Stop").show()
    };

    function ChangeUrl(){
        iframe = document.getElementById("outSideWeb");  
        iframe.src = url2;
        times = times + 1
        $("#times").html(times)
        console.log(times)
        $("#Hit2").show()
        $("#outSideWeb").attr('src', $("#outSideWeb").attr('src'))
    };

</script>
</body>
</html>